% Dynamic bank run model 
% Banl leverage choice only
% written by Daisuke Ikeda

clear
close all
         
% Solve model
dynare model
variable_index

% Impulse responses
T = 4*12;
tt = 1:1:T;
nc = 3;
nr = 3;
figure
j=1;
subplot(nr,nc,j)
plot(tt,oo_.irfs.yU_ea(tt)./oo_.steady_state(yU).*100,'linewidth',2)
title('Output (%)')
j=j+1;
subplot(nr,nc,j)
plot(tt,oo_.irfs.cU_ea(tt)./oo_.steady_state(cU).*100,'linewidth',2)
title('Consumption (%)')
j=j+1;
subplot(nr,nc,j)
plot(tt,oo_.irfs.iU_ea(tt)./oo_.steady_state(iU).*100,'linewidth',2)
title('Investment (%)')
j=j+1;
subplot(nr,nc,j)
plot(tt,oo_.irfs.hU_ea(tt)./oo_.steady_state(hU).*100,'linewidth',2)
title('Hours worked (%)')
j=j+1;
subplot(nr,nc,j)
plot(tt,oo_.irfs.nU_ea(tt)./oo_.steady_state(nU).*100,'linewidth',2)
title('Bank net worth (%)')
j=j+1;
subplot(nr,nc,j)
plot(tt,oo_.irfs.LU_ea(tt)./oo_.steady_state(LU).*100,'linewidth',2)
title('Leverage (%)')
j=j+1;
subplot(nr,nc,j)
plot(tt,(oo_.irfs.RbU_ea(tt)).*400,'linewidth',2)
title('Interest rate (APR diff)')
j=j+1;
subplot(nr,nc,j)
plot(tt,(oo_.irfs.PU_ea(tt)).*400,'linewidth',2)
title('Crisis probability (APR diff)')
j=j+1;
subplot(nr,nc,j)
%tt=2:1:T+1;
plot(tt,oo_.irfs.xiU_ea(tt)+oo_.steady_state(xiU)-1,'linewidth',2)
title('Crisis threshold (<0 => crisis)')
